#include<iostream>
using namespace std;
typedef long long LL;
LL l, r;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> l >> r;
		LL ans1 = 0;
		LL ans2 = 0;
		if ((l + r) % 2 == 0) {
			ans1 = (l + r) >> 1;
			ans2 = (r - l + 1);
		}
		else {
			ans1 = (r - l + 1) / 2;
			ans2 = l + r;
		}
		cout << (ans1 % 9 * ans2 % 9) % 9 << endl;
	}
	return 0;
}